﻿/**********************************************************************
 * * 版权所有：@ Getlayer 
 * * 类 名 称： 
 * * 功    能： 
 * * 作    者：Getlayer
 * * 电子邮箱：2854989822@qq.com
 * * 创建日期： 2014-1-20 19:20:18
 *  *********************************************************************/
using System;
using System.Data.Common;
using System.Data;
using System.Collections.Generic;


namespace Getlayer.DBUtility
{
    public static class ProviderFactory
    {
        internal static  Dictionary<ProviderType, string> providerInvariantNames = new Dictionary<ProviderType, string>();
        /// <summary>
        /// 加载全局引用，数据库客户端dll
        /// </summary>
         static ProviderFactory()
        {
            providerInvariantNames.Add(ProviderType.Oracle, "System.Data.OracleClient");
            providerInvariantNames.Add(ProviderType.SqlServer, "System.Data.SqlClient");
            providerInvariantNames.Add(ProviderType.MySql, "MySql.Data");
            providerInvariantNames.Add(ProviderType.OleDb, "System.Data.OleDb");
            providerInvariantNames.Add(ProviderType.Firebird, "FirebirdSql.Data.FirebirdClient");
            providerInvariantNames.Add(ProviderType.Odbc, "System.Data.Odbc");
            providerInvariantNames.Add(ProviderType.SQLite, "System.Data.SQLite");
        }
        /// <summary>
        /// 根据数据库类型，获取ProviderFactory
        /// </summary>
        /// <param name="dbprovidertype">数据类型</param>
        /// <returns>DbProviderFactory</returns>
        public static DbProviderFactory GetProviderFactory(ProviderType dbprovidertype)
        {
            if (providerInvariantNames.ContainsKey(dbprovidertype))
            {
                return DbProviderFactories.GetFactory(providerInvariantNames[dbprovidertype]);
            }
            else
                return null;
        }
        
    
    }
    /// <summary>
    /// 数据库适配器类型
    /// </summary>
    public enum ProviderType : byte
    {
        SqlServer,
        MySql,
        SQLite,
        Oracle,
        Odbc,
        OleDb,
        Firebird


    }
  
}
